//
//  JMWithdrawalsTVController.m
//  jiMuOperate
//
//  Created by 胡梅方 on 16/4/29.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMWithdrawalsTVController.h"

@interface JMWithdrawalsTVController ()<UITextFieldDelegate>
@property(nonatomic,weak)UIButton *withdrawalBtn;
@property(nonatomic,weak)UILabel *pineNutNumLab;
@property(nonatomic,weak)UILabel *toCountNumLab;
@property(nonatomic,weak)UILabel *counterFeeLab;
@end

@implementation JMWithdrawalsTVController
{
    UITextField* withdrawalNums;
    UITextField* paymentPwd;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.scrollEnabled = NO;
     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 3)];
    self.tableView.tableHeaderView = view;
    self.tableView.backgroundColor = BACKCOLOR;
//     self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 10) style:UITableViewStyleGrouped];
 
   
    self.navigationItem.title = @"提现";
    UITapGestureRecognizer *singleRecognizer;
    singleRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTapFrom)];
    singleRecognizer.numberOfTapsRequired = 1;
    [self.tableView addGestureRecognizer:singleRecognizer];
    [self createButton];
    
}
- (void)handleSingleTapFrom
{
    [paymentPwd resignFirstResponder];
    [withdrawalNums resignFirstResponder];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 3;
    }else {
    return 3;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *withdrawalsCell = @"withdrawalsCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:withdrawalsCell];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:withdrawalsCell];
    }
    
    CGFloat imageH = 40;
    UILabel *describLab = [ARC createLabelWithFrame:CGRectMake(10, 5, imageH*4, imageH) Font:15 Text:nil];
    describLab.textColor = [UIColor blackColor];
    describLab.textAlignment = NSTextAlignmentLeft;
    describLab.frame = [ToolViewAndData MyAutoLayout:describLab];
    [cell.contentView addSubview:describLab];

    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
            {
                UILabel *pinNutNum = [[UILabel alloc]init];
                [describLab addSubview:pinNutNum];
                self.pineNutNumLab = pinNutNum;
                describLab.text = [NSString stringWithFormat:@"现有松籽:%@个",pinNutNum.text];
                break;
            }
            case 1:
                describLab.text = @"提现数量：";
                if (!withdrawalNums) {
                    withdrawalNums = [self addWithdrawalNumFieldWithFrame:CGRectMake(imageH*2, 0, imageH*6, CELLHIGHT)];
                    
                    [cell.contentView  addSubview:withdrawalNums];
                }
                break;
            case 2:
            {

                UILabel *toCountNum = [[UILabel alloc]init];
                [describLab addSubview:toCountNum];
                self.toCountNumLab = toCountNum;
                describLab.text = [NSString stringWithFormat:@"到帐金额:%@元",toCountNum.text];
                break;
            }
            default:
                break;
        }
    }else {
        switch (indexPath.row) {
            case 0:
                
                
                break;
            case 1:{
                UILabel *counterFeeNum = [[UILabel alloc]init];
                [describLab addSubview:counterFeeNum];
                describLab.text = [NSString stringWithFormat:@"手 续 费:%@元",counterFeeNum.text];
                self.counterFeeLab = counterFeeNum;
                break;
            }
            case 2:
                describLab.text = @"支付密码：";
                if (!paymentPwd) {
                    paymentPwd = [self addPaymentPwdFieldWithFrame:CGRectMake(imageH*2, 0, imageH*6, CELLHIGHT)];
                    
                    [cell.contentView  addSubview:paymentPwd];
                }
                
                break;
            default:
                break;
        }
    }
    [cell.contentView addSubview:[ARC createImageViewLineWithHeigt:1]];
    
    return cell;
}


-(JMTextField*)addWithdrawalNumFieldWithFrame:(CGRect)frame
{
    JMTextField *textField = [JMTextField createTextFieldWithFrame:frame
                                                              Font:16
                                                       Placeholder:@"请输入数量"
                                                   SecureTextEntry:NO
                                                         TextColor:[UIColor blackColor]];
    textField.keyboardType =  UIKeyboardTypeDefault;
    textField.delegate = self;
    textField.frame =  [ToolViewAndData MyAutoLayout:textField];
    return  textField;
    
    
    
}
-(JMTextField*)addPaymentPwdFieldWithFrame:(CGRect)frame
{
    JMTextField *textField = [JMTextField createTextFieldWithFrame:frame
                                                              Font:16
                                                       Placeholder:@"请输入支付密码"
                                                   SecureTextEntry:YES
                                                         TextColor:[UIColor blackColor]];
    textField.keyboardType =  UIKeyboardTypeDefault;
    textField.delegate = self;
    textField.frame =  [ToolViewAndData MyAutoLayout:textField];
    return  textField;
 
    
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [withdrawalNums resignFirstResponder];
    [paymentPwd resignFirstResponder];
    return YES;
}
- (void)createButton{
    
    CGFloat btnX = 310;
    CGFloat btnH = 40;
    
    
    UIButton* withdrawalBtn = [ARC createButtonWithFrame:CGRectMake(30,btnX, 260, btnH)
                                             Target:self
                                                Sel:@selector(withdrawalsBtnClick:)
                                              Title:@"提 现"];
    [withdrawalBtn setBackgroundImage:[UIImage imageNamed:@"logoin_btn"] forState:UIControlStateNormal];
    withdrawalBtn.frame = [ToolViewAndData MyAutoLayout:withdrawalBtn];
    [withdrawalBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
    withdrawalBtn.tintColor=[UIColor whiteColor];
    [self.view addSubview:withdrawalBtn];
}
-(void)withdrawalsBtnClick:(UIButton*)btn
{
    
}
@end
